import JsonSeriType from "./core/JsonSeriType"

import classLoader from "./core/classLoader"

const DEFAULT_CLASS_PAGE = "_default_class_page";

const FLOW_NODE_CONSTANTS = {
	nodeWare:{},
	nodeList:[],
	creatorWare:{},
};
function load(flowNode,creator){
	FLOW_NODE_CONSTANTS.nodeWare[flowNode.flowType] = flowNode;
	FLOW_NODE_CONSTANTS.creatorWare[flowNode.flowType] = creator;
	FLOW_NODE_CONSTANTS.nodeList.push(flowNode);
	loadClass(flowNode,creator);
}
function loadClass(flowNode,creator){
	if(creator !=null){
		let cobj = creator();
		if(cobj != null && cobj.seriType != null){
			classLoader.loadClass(cobj.seriType.type,flowNode,creator,cobj.seriType.page);
		}else{
			loadClass(flowNode.flowType,flowNode,creator,DEFAULT_CLASS_PAGE);
		}
	}
}
function loadAll(){
	
	classLoader.loadClass(JsonSeriType._seriType.type,JsonSeriType,function(params){
		return new JsonSeriType(params);
	},JsonSeriType._seriType.page);
	
}
function getAll(){
	return FLOW_NODE_CONSTANTS.nodeList;
}

function getAllGroup(){
	return flowGroup.groupAll(getAllFlow());
}

function getGen(classType){
	return FLOW_NODE_CONSTANTS.nodeWare[classType];
}

function createUUid(type){
	return "type."+type+"." + Math.random().toString(36).substr(3, 10)
	
}

function getCreator(type, def){
	return FLOW_NODE_CONSTANTS.creatorWare[type] || def;
}

function createByType(type){
	return getCreator(type)(createUUid(type));
}



export default {
	getAllGroup,
	getAll,
	loadAll,
	load,
	getGen,
	createUUid,
	createByType
	
};